package com.stone.activemqcase.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;
import java.util.UUID;

/**
 * boot整合activemq
 */
@EnableJms
@Component
public class BootTopicProducer {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Topic topic;

    /**
     * 普通推送，运行一次发送一次
     */
    public void producer(){
        jmsMessagingTemplate.convertAndSend(topic,"*****************************>"+ UUID.randomUUID().toString().substring(0,9));
    }

    /**
     * 定时任务 间隔三秒推送消息
     */
    @Scheduled(fixedDelay = 30000)
    public void producerScheduled(){
        jmsMessagingTemplate.convertAndSend(topic,"*****************************>"+ UUID.randomUUID().toString().substring(0,9));
    }
}
